package esoft2.ipleiria.mybio;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class ParticipantsActivity extends Activity {

    private boolean isCheckedIn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_participants);

        Intent intent = getIntent();
        isCheckedIn = intent.getBooleanExtra(MainActivity.ISCHECKEDIN, false);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_participants, menu);

        MenuItem id = menu.findItem(R.id.action_checkin);

        if (id != null) {
            updateMenuItemCheckedIn(id);
        }


        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        if (id == R.id.action_checkin) {
            isCheckedIn = !isCheckedIn;
            updateMenuItemCheckedIn(item);
        }

        return super.onOptionsItemSelected(item);
    }

    private void updateMenuItemCheckedIn(MenuItem menuItemCheckedIn) {
        menuItemCheckedIn.setIcon(isCheckedIn ? R.drawable.ic_action_group : R.drawable.ic_action_person);
    }
}
